gcc编译 |
您所在的位置:网站首页 › linux gcc是什么意思 › gcc编译 |
先来看看gcc官方手册吧 These ‘-m’ switches are supported in addition to the above on x86-64 processors in 64-bit environments. -m32 -m64 -mx32 -m16 -miamcu Generate code for a 16-bit, 32-bit or 64-bit environment. The ‘-m32’ option sets int, long, and pointer types to 32 bits, and generates code that runs on any i386 system. The ‘-m64’ option sets int to 32 bits and long and pointer types to 64 bits, and generates code for the x86-64 architecture. For Darwin only the ‘-m64’ option also turns off the ‘-fno-pic’ and ‘-mdynamic-no-pic’ options. The ‘-mx32’ option sets int, long, and pointer types to 32 bits, and generates code for the x86-64 architecture. The ‘-m16’ option is the same as ‘-m32’, except for that it outputs the .code16gcc assembly directive at the beginning of the assembly output so that the binary can run in 16-bit mode. The ‘-miamcu’ option generates code which conforms to Intel MCU psABI. It requires the ‘-m32’ option to be turned on. 执行编译的程序需要安装32位lib: $sudo apt-get install lib32ncurses5 lib32z1 编译时需安装multilib: sudo apt-get install gcc-multilib g++-multilib 在我的电脑上-m32能够运行,-mx32需要内核支持,在编译内核时有mx32的选项,CentOS7内核和GCC都没开启支持mx32,Debian9内核没开启,但gcc支持 下面是elf读取出来的信息: -mx32:在64位系统中,指针和long都是64位的(此处只讨论linux,Windows不是),因此程序可以使用的内存大小可以远远大于4GiB。但是很多程序并不需要4GiB以上内存,这样内存地址只使用了低4字节造成一定的浪费,而且对于x86的CPU(准确的说是amd64或x86-64,不含IA64),64位数据运算速度远远慢于32位数据,指针和long是32位既浪费了高4字节的空间,又拖累了运行速度,于是有人搞出了指针和long是32位的mx32:你同样可以使用INT64这样的8字节数据,但编译出的程序体积更小,运行速度更快。 $ g++ size.cpp -O3 -mx32 -o size $ readelf -h ./size ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: DYN (Shared object file) Machine: Advanced Micro Devices X86-64 Version: 0x1 Entry point address: 0x7e0 Start of program headers: 52 (bytes into file) Start of section headers: 6600 (bytes into file) Flags: 0x0 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 9 Size of section headers: 40 (bytes) Number of section headers: 31 Section header string table index: 30 -m32:编译出来的是32位程序,既可以在32位操作系统运行,又可以在64位操作系统运行。$ g++ size.cpp -O3 -m32 -o size $ readelf -h ./size ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: DYN (Shared object file) Machine: Intel 80386 Version: 0x1 Entry point address: 0x818 Start of program headers: 52 (bytes into file) Start of section headers: 6668 (bytes into file) Flags: 0x0 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 9 Size of section headers: 40 (bytes) Number of section headers: 31 Section header string table index: 30 $ g++ size.cpp -O3 -o size $ readelf -h ./size ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: DYN (Shared object file) Machine: Advanced Micro Devices X86-64 Version: 0x1 Entry point address: 0xa60 Start of program headers: 64 (bytes into file) Start of section headers: 11320 (bytes into file) Flags: 0x0 Size of this header: 64 (bytes) Size of program headers: 56 (bytes) Number of program headers: 9 Size of section headers: 64 (bytes) Number of section headers: 31 Section header string table index: 30 -m16,只有在32位的linux上才能使用,同样需要在编译内核时做设置,只有在32位内核中才有该选项,gcc同样也只有32位版本才支持。几乎没人使用,除了某些16位的嵌入式 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |